package com.alibaba.citrus.ots.sales.plan.converter;

import com.alibaba.citrus.ots.sales.plan.model.features.SalesPlanScItemFeatures;
import com.alibaba.citrus.ots.sales.plan.sdo.SalesPlanStatScItemSDO;
import com.alibaba.fastjson.JSONObject;
import com.epoch.app.bcots.sales_plan.planscitem.model.PlanScItem;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author luyi
 * @date 2021/9/24 12:42 上午
 */
public class PlanScItemConverter {


    public static PlanScItem planScItemSdoToDo(SalesPlanStatScItemSDO request){
        if (Objects.isNull(request)){
            return null;
        }
        PlanScItem target = new PlanScItem();
        BeanUtils.copyProperties(request,target);
//        SalesPlanScItemFeatures features = new SalesPlanScItemFeatures();
///*        features.setScItemName(request.getScItemName());*/
//        target.setFeatures(JSONObject.toJSONString(features));
        return target;
    }

    public static SalesPlanStatScItemSDO planScItemDoToSdo(PlanScItem request){
        if (Objects.isNull(request)){
            return null;
        }
        SalesPlanStatScItemSDO target = new SalesPlanStatScItemSDO();
        BeanUtils.copyProperties(request,target);
//        if (!Objects.isNull(request.getFeatures())){
//            SalesPlanScItemFeatures features = JSONObject.parseObject(request.getFeatures(), SalesPlanScItemFeatures.class);
///*            target.setScItemName(features.getScItemName());*/
//        }
        return target;
    }

    public static List<PlanScItem> planScItemSdoToDo(List<SalesPlanStatScItemSDO> requestList){
        if (CollectionUtils.isEmpty(requestList)){
            return null;
        }
        List<PlanScItem> result = Lists.newArrayListWithCapacity(requestList.size());
        for (SalesPlanStatScItemSDO request : requestList) {
            result.add(planScItemSdoToDo(request));
        }
        return result;
    }

    public static List<SalesPlanStatScItemSDO> planScItemDoToSdo(List<PlanScItem> requestList){
        if (CollectionUtils.isEmpty(requestList)){
            return null;
        }
        List<SalesPlanStatScItemSDO> result = Lists.newArrayListWithCapacity(requestList.size());
        for (PlanScItem request : requestList) {
            result.add(planScItemDoToSdo(request));
        }
        return result;
    }


}
